package Data::Conveyor::Ticket::Processor::Conveyor;

# $Id: Conveyor.pm 13653 2007-10-22 09:11:20Z gr $

use strict;
use warnings;


our $VERSION = '0.02';


use base 'Class::Scaffold::Storable';


__PACKAGE__
    ->mk_framework_object_accessors(ticket => 'ticket')
    ->mk_scalar_accessors(qw(poll_delegate))
    ->mk_boolean_accessors(qw(transactional_authority));


# the poll delegate allows the upper service layer to interrupt processing
# by throwing an exception, if it thinks it is necessary.

use constant DEFAULTS => (transactional_authority => 1);


sub run {
    my $self = shift;

    my $previous_stage = '';
    while ($self->ticket->stage ne $previous_stage) {

        last if $self->ticket->stage
             eq $self->delegate->FINAL_TICKET_STAGE;

        $previous_stage = $self->ticket->stage;

        if ($self->poll_delegate &&
            $self->poll_delegate->can('callback')) {
            $self->poll_delegate->callback($self->ticket);
        }

        # We need to set the ticket to active, because it won't have been
        # open()ed - we just process a ticket from start to end, without
        # repeatedly writing and re-reading it.

        $self->ticket->stage->set_active;
        $self->delegate->make_obj('ticket_dispatcher')->new(
            transactional_authority => $self->transactional_authority)->
            dispatch($self->ticket);


    }
    $self->ticket->store;
}


1;


__END__

{% USE p = PodGenerated %}

=head1 NAME

{% p.package %} - stage-based conveyor-belt-like ticket handling system

=head1 SYNOPSIS

    {% p.package %}->new;

=head1 DESCRIPTION

None yet. This is an early release; fully functional, but undocumented. The
next release will have more documentation.

=head1 METHODS

=over 4

{% p.write_methods %}

=back

{% p.write_inheritance %}

{% PROCESS standard_pod %}

=cut

